package com.xiaohudie.SGGJUC;

import java.util.concurrent.TimeUnit;

/**
 * @Author xiao hu die
 * @Date 2022/3/12 11:39
 * @Version 1.0
 */
public class TestVolatile {
 /**volatile会让线程感知主内存中的值已经被修改了*/
 private static  volatile Boolean a =true;
 public static void main(String[] args) {
 new Thread(()->{
  while (a==true){
   System.out.println(Thread.currentThread().getName());
  }
 }).start();
  try {
   TimeUnit.SECONDS.sleep(1);
  } catch (InterruptedException e) {
   e.printStackTrace();
  }
  a=false;
  System.out.println(Thread.currentThread().getName());
 }
}
